export default {
  prefix(key){
    return channel+'_'+key
  },
  set(key,value){
    //console.log("set "+key,value)
    try{
      window.sessionStorage.setItem(this.prefix(key),JSON.stringify({"data":value}))
    }catch (e) {
      console.log("set lockr err",e)
    }
  },
  get(key){
    let result = null
    let val = window.sessionStorage.getItem(this.prefix(key))
    if(val){
      try {
        let obj = JSON.parse(val)
        if(obj && obj.data){
          result = obj.data
        }
      } catch (e) {
         console.log("lockr get data parse err",e)
      }
    }
    return result
  },
  del(key){
    try {
      window.sessionStorage.removeItem(this.prefix(key))
    } catch (e) {
      console.log("lockr del val err",e)
    }
  },
  setLocal(key,value){
    try{
      window.localStorage.setItem(this.prefix(key),JSON.stringify({"data":value}))
    }catch (e) {
      console.log("setLocal err",e)
    }
  },
  getLocal(key){
    let result = null
    let val = window.localStorage.getItem(this.prefix(key))
    if(val){
      try {
        let obj = JSON.parse(val)
        if(obj && obj.data){
          result = obj.data
        }
      } catch (e) {
        console.log("getLocal get data parse err",e)
      }
    }
    return result
  }
}
